package com.restaurant.serviceimpl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Menucategory;
import com.restaurant.service.MenucategoryService;

public class MenucategoryServiceImpl implements MenucategoryService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menucategory addOrModify( Menucategory objMenucategory ) {
       return ( Menucategory ) hibernateTemplate.merge( objMenucategory );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menucategory deleteRecord( Menucategory objMenucategory ) {
       hibernateTemplate.delete( objMenucategory );
       return objMenucategory;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menucategory modifyRecord( Menucategory objMenucategory ) {
       return ( Menucategory ) hibernateTemplate.merge( objMenucategory );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Menucategory> loadAll() {
       return (List<Menucategory>)hibernateTemplate.findByNamedQuery( "Menucategory.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menucategory loadByPrimaryKey( Long primaryKey ) {
       return (Menucategory) hibernateTemplate.get( Menucategory.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Menucategory deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Menucategory> loadByHql(String query) {
	   return ( List<Menucategory> ) hibernateTemplate.find( query );
   }
}